package com.min.juc.lock8;

import java.util.concurrent.TimeUnit;

public class Test1 {
    public static void main(String[] args) {
        Phone1 phone = new Phone1();

        // A,B线程肯定会顺序执行
        // synchronized 哪个线程先拿到锁,会锁住对象
        // 必须执行有synchronized 才会拿到锁
        new Thread(()->{
            phone.sendSms();
        },"A").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            phone.call();
        },"B").start();


    }
}


 class Phone1 {

    public synchronized void  sendSms(){
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("发短信");
    }
    public synchronized void  call(){
        System.out.println("打电话");
    }
}